package LeetCode._顺序刷题;

import java.util.Arrays;

/**
 * @Author: yqy
 * @Date: 2022/06/06/17:09
 * @Description:
 */
public class _242 {
    public static void main(String[] args) {
        _242 v = new _242();
        boolean flag = v.isAnagramPlus("rat", "car");
        System.out.println(flag);

    }
    public boolean isAnagramPlus(String s, String t) {
        if(s.length()!=t.length()){
            return false;
        }
        char[] schar = s.toCharArray();
        char[] tchar = t.toCharArray();
        Arrays.sort(schar);
        Arrays.sort(tchar);
        int i=0;
        boolean flag=true;
        while(i< schar.length){
            if (schar[i]!=tchar[i]){
                flag=false;
                break;
            }
            i++;
        }
        return flag;
    }
    public boolean isAnagram(String s, String t) {
        if(s.length()!=t.length()){
            return false;
        }
        int sum=0;
        for(int i=0;i<s.length();i++){
            sum+=s.charAt(i);
        }
        for(int i=0;i<t.length();i++){
            sum-=s.charAt(i);
        }
        return sum==0;
    }

}
